package com.jsshse.dao.sys.impl;

import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Repository;

import com.jsshse.bean.UserRoleInfo;
import com.jsshse.dao.base.impl.BaseDaoImpl;
import com.jsshse.dao.sys.UserDaoI;

@Repository("userDao")
public class UserDaoImpl <T> extends BaseDaoImpl<T> implements UserDaoI<T>{
	private static Logger log = Logger.getLogger(UserDaoImpl.class);
	@Override
	
	public boolean add(Map param) {
		String v = (String) this.getSqlTemp().insert("sys.insertUser", param);
		return v != null ? true : false;
	}
	@Override
	
	public boolean delete(String uid) {
		int res = this.getSqlTemp().delete("sys.deleteUserByID", uid);
		return res > 0 ? true : false;
	}
	@Override
	
	public boolean update(Map param) {
		int res =this.getSqlTemp().update("sys.updateUser",param);
		return res > 0 ? true : false;
	}
	@Override
	public List queryForListByPage(Object paramCls, int startRow, int pageRows) {
		log.debug(this.getSqlTemp());
		return  this.getSqlTemp().queryForList("sys.queryUserList",
				paramCls, startRow, pageRows);
	}
	@Override
	public int queryForListCnt(Object paramCls) {
		return ((Integer) this.getSqlTemp().queryForObject(
				"sys.queryUserCnt", paramCls)).intValue();
	}
	
	
	public boolean updateUserInfo(Map param) {
		int res =this.getSqlTemp().update("sys.updateUserInfo",param);
		return res > 0 ? true : false;
	}
	
	public boolean addUserRole(Map param) {
		String v = (String) this.getSqlTemp().insert("sys.insertUserRole", param);
		return v != null ? true : false;
	}
	
	public boolean deleteUserRole(String uid) {
		int res = this.getSqlTemp().delete("sys.deleteUserRoleByID", uid);
		return res > 0 ? true : false;
	}
	
	public boolean updateUserRole(Map param) {
		int res =this.getSqlTemp().update("sys.updatetUserRole",param);
		return res > 0 ? true : false;
	}
	public Map queryById(String uid) {
		log.debug(this.getSqlTemp());
		return (Map) this.getSqlTemp().queryForObject("sys.queryUserById", uid);
	}
	
	
	public int queryUserRoleCnt(String paramCls) {
		log.debug(this.getSqlTemp());
		return ((Integer) this.getSqlTemp().queryForObject(
				"sys.queryUserRoleCnt", paramCls)).intValue();
	}
	
	public UserRoleInfo queryUserRoleInfo(String paramCls) {
		return (UserRoleInfo) this.getSqlTemp().queryForObject("sys.queryUserRoleInfo", paramCls);
	}
}
